<template>
	<view>
		<!-- 图片显示区域 -->
		<view class="image-container">
			<image :src="imageUrl" mode="aspectFill" class="circular-image"></image>
		</view>
		<!-- 按钮区域 -->
		<view class="button-group">
			<button class="custom-btn" @click="chooseImage">选择图片显示</button>
			<button class="custom-btn" @click="previewImage">预览图片</button>
			<button class="custom-btn" @click="getImageInfo">获取图片信息</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageUrl: 'https://via.placeholder.com/100', // 初始图片地址，可替换为示例图地址
				selectedImagePath: '' // 存储选择的图片临时路径
			}
		},
		methods: {
			chooseImage() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						this.selectedImagePath = res.tempFilePaths[0];
						this.imageUrl = res.tempFilePaths[0];
					}
				});
			},
			previewImage() {
				if (this.selectedImagePath) {
					uni.previewImage({
						current: this.selectedImagePath,
						urls: [this.selectedImagePath]
					});
				} else {
					uni.showToast({
						title: '请先选择图片',
						icon: 'none'
					});
				}
			},
			getImageInfo() {
				if (this.selectedImagePath) {
					uni.getImageInfo({
						src: this.selectedImagePath,
						success: (info) => {
							uni.showModal({
								title: '图片信息',
								content: `宽度：${info.width}px\n高度：${info.height}px\n格式：${info.type}\n路径：${info.path}`,
								showCancel: false
							});
						}
					});
				} else {
					uni.showToast({
						title: '请先选择图片',
						icon: 'none'
					});
				}
			}
		}
	}
</script>

<style scoped>
	.image-container {
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 20px 0;
	}
	.circular-image {
		width: 120px;
		height: 120px;
		border-radius: 50%;
	}
	.button-group {
		width: 90%;
		margin: 0 auto;
	}
	.custom-btn {
		margin-bottom: 15px;
		border-radius: 6px;
	}
</style>